package com.ruoyi.community.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.community.domain.HouseHistory;
import com.ruoyi.community.domain.vo.HouseVo;
import com.ruoyi.community.domain.vo.HouseVos;
import com.ruoyi.community.mapper.HouseHistoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.community.mapper.HouseMapper;
import com.ruoyi.community.domain.House;
import com.ruoyi.community.service.IHouseService;

/**
 * 房屋Service业务层处理
 *
 * @author lj
 * @date 2022-02-22
 */
@Service
public class HouseServiceImpl implements IHouseService {
    @Autowired
    private HouseMapper houseMapper;
    @Autowired
    private HouseHistoryMapper houseHistoryMapper;

    /**
     * 查询房屋
     *
     * @param id 房屋主键
     * @return 房屋
     */
    @Override
    public House selectHouseById(Long id) {
        return houseMapper.selectHouseById(id);
    }

    /**
     * 查询房屋列表
     *
     * @param house 房屋
     * @return 房屋
     */
    @Override
    public List<House> selectHouseList(House house) {
        return houseMapper.selectHouseList(house);
    }

    @Override
    public List<HouseVos> selectHouseLists(House house) {
        return houseMapper.selectHouseLists(house);
    }

    /**
     * 新增房屋
     *
     * @param house 房屋
     * @return 结果
     */
    @Override
    public int insertHouse(House house) {
        house.setCreatTime(DateUtils.getNowDate());
        house.setUpdateTime(DateUtils.getNowDate());
        house.setDelFlag(0);
        return houseMapper.insertHouse(house);
    }
    @Override
    public int insertHouseVo(HouseVo houseVo) {
        House house=new House();
        house.setHousingId(houseVo.getHousingId());
        house.setUsername(houseVo.getUsername());
        house.setPhonenumber(houseVo.getPhonenumber());
        house.setIdentityCard(houseVo.getIdentityCard());
        house.setArea(houseVo.getArea());
        house.setAddress(houseVo.getAddress());
        house.setCreatTime(DateUtils.getNowDate());
        house.setUpdateTime(DateUtils.getNowDate());
        house.setDelFlag(0);
        int i = houseMapper.insertHouse(house);
        HouseHistory houseHistory=new HouseHistory();
        houseHistory.setUserId(houseVo.getUserId());
        houseHistory.setHouseId(house.getId());
        houseHistory.setCreatTime(DateUtils.getNowDate());
        houseHistory.setUpdateTime(DateUtils.getNowDate());
        houseHistory.setDelFlag(0);
        houseHistoryMapper.insertHouseHistory(houseHistory);
        return i ;
    }

    /**
     * 修改房屋
     *
     * @param house 房屋
     * @return 结果
     */
    @Override
    public int updateHouse(House house) {
        house.setUpdateTime(DateUtils.getNowDate());
        return houseMapper.updateHouse(house);
    }

    /**
     * 批量删除房屋
     *
     * @param ids 需要删除的房屋主键
     * @return 结果
     */
    @Override
    public int deleteHouseByIds(Long[] ids) {
        return houseMapper.deleteHouseByIds(ids);
    }

    /**
     * 删除房屋信息
     *
     * @param id 房屋主键
     * @return 结果
     */
    @Override
    public int deleteHouseById(Long id) {
        return houseMapper.deleteHouseById(id);
    }

    @Override
    public int updateHouseByIds(Long[] ids) {
        return houseMapper.updateHouseByIds(ids);
    }

    @Override
    public List<HouseVo> myHouse(Long userId) {
        return houseMapper.myHouse(userId);
    }
}
